package za.org.jcicada.datastore.impl.jdbc;

import java.net.URI;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public final class JDBC {
	
	private static Map<URI, JDBC> instances = new HashMap<URI, JDBC>();
	
	private URI connectionURI;
	
	private JDBC(URI connectionURI) {
		this.connectionURI = connectionURI;
	}
	
	synchronized static JDBC getInstance(URI connectionURI) {
		if (!instances.containsKey(connectionURI)) {
			instances.put(connectionURI, new JDBC(connectionURI));
		}
		return instances.get(connectionURI);
	}
	
	public Connection getConnection() throws SQLException {
		return DriverManager.getConnection(connectionURI.toString());
	}

}
